//
//  XYMainController.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 15/12/26.
//  Copyright © 2015年 cn.weibo. All rights reserved.
//

import UIKit

class XYMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addViewControllers()
        
        let tabBar = XYTabBar()
        // MARK: 监听compose 的点击
        tabBar.didClickComposeBtnBlock = {
            
            let pop = XYComposePopView()
            pop.show(self)
        }
        
        setValue(tabBar, forKeyPath: "tabBar")
        
    }

    
    private func addViewControllers() {
        
        addChildViewController(XYHomeController(), title: "首页", image: "tabbar_home")
        addChildViewController(XYMessageController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(XYDiscoverController(), title: "发现", image: "tabbar_discover")
        addChildViewController(XYProfileController(), title: "我", image: "tabbar_profile")
    }
    private func addChildViewController(childController: UIViewController,title:String, image:String) {
        
        childController.tabBarItem = XYTabBarItem()
        childController.title = title

        childController.tabBarItem.image = UIImage(named: image)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(XYNavController(rootViewController:childController))
        
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
